package mainKTY;

import java.util.*;


public class ManagerDeployee {


    private List<Deployee> deployeeList;
    private Map<Integer, Deployee> allDeployees;
    private int currentId;
    private ManagerSalary mS;
    private static final String PATH = "D:\\Deployees.txt";



    public void persSalary(Deployee dep, double sal){
        mS = new ManagerSalary();
         deployeeList = new ArrayList<Deployee>();
         Deployee [] al = (Deployee[]) deployeeList.toArray();
        dep.setSalary((sal/mS.midKtu(al))*dep.getKtu());
    }

    public boolean addDeployees(List<Deployee> lD){
        try {
            FileMaster.writeToFile(lD, PATH);
            return true;
        }   catch (Exception e) {
            e.printStackTrace();
            return false;
        }


    }

    public void midPersKtu(Deployee men,int day,int dayBeIll){
        men.setKtu((day*men.getKtu()+(dayBeIll*(men.getKtu()-0.2)))/(day+dayBeIll));
    }

    public String getDeployeeList (){
       return allDeployees.values().toString();
    }

    public void loadAllDep (){
        allDeployees = new TreeMap<Integer, Deployee>();
        List<String> fromFile = FileMaster.getFileContent(PATH);
        Iterator<String> iter = fromFile.iterator();
        Deployee depTmp;
        String tmp;
        int maxID =0;
        while (iter.hasNext()){
            tmp = iter.next();
            depTmp = new Deployee(tmp);
            allDeployees.put(maxID++,depTmp);
            if (depTmp.getId() > maxID)
                maxID=depTmp.getId();
        }
        this.currentId = maxID;

    }
    }

